<script>
    var select_arr={};
</script>
<div class="bjui-pageContent">
<form action="/admin/order/createOrderSubmit" id="create_order" data-toggle="ajaxform" data-alertmsg="false">
    <input type="hidden" name="order_pre_id" value="{{$orderPreId}}">
    <div class="bjui-row col-2">
        <h3>基础信息</h3>
        @foreach ($orderBaseFieldList as $orderBaseFieldRow)
            @if($orderBaseFieldRow['field_type'] == 5){{--文本+选择--}}
            <label class="row-label">{{$orderBaseFieldRow['title']}}</label>
            <div class="row-input @if ($orderBaseFieldRow['is_must'] == 1) required @endif">
                <input style="width:80%" name="base_{{$orderBaseFieldRow['field_name']}}[]"  value="@if(isset($orderBaseFieldRow['default_value'])) {{$orderBaseFieldRow['default_value']}} @endif" data-rule="@if ($orderBaseFieldRow['is_must'] == 1) required @endif" type="text">

                <select name="base_{{$orderBaseFieldRow['field_name']}}[]" data-toggle="selectpicker" data-rule="@if ($orderBaseFieldRow['is_must'] == 1) required @endif">
                    <option value="">请选择</option>{{--空选项--}}
                    @foreach ($orderBaseFieldRow['field_unit'] as $unitValue)
                        <option value="{{$unitValue['title']}}" @if(isset($orderBaseFieldRow['default_unit_title']) && $orderBaseFieldRow['default_unit_title'] == $unitValue['title']) selected="" @endif>{{$unitValue['title']}}</option>
                    @endforeach
                </select>
            </div>

            @elseif($orderBaseFieldRow['field_type'] == 6){{--开关按钮--}}
            <label class="row-label">{{$orderBaseFieldRow['title']}}</label>
            <div class="row-input @if ($orderBaseFieldRow['is_must'] == 1) required @endif">
                <input name="base_{{$orderBaseFieldRow['field_name']}}" @if(isset($orderBaseFieldRow['default_value']) && ($orderBaseFieldRow['default_value'] == 1 )) checked="" @endif data-toggle="icheck" value="1" data-rule="@if ($orderBaseFieldRow['is_must'] == 1) required @endif" data-label="是" type="radio">
                <input name="base_{{$orderBaseFieldRow['field_name']}}" @if(isset($orderBaseFieldRow['default_value']) && ($orderBaseFieldRow['default_value'] == 0 )) checked="" @endif  data-toggle="icheck" value="0" data-label="否" type="radio">
            </div>

            @elseif($orderBaseFieldRow['field_type'] == 7){{--日期--}}
            <label class="row-label">{{$orderBaseFieldRow['title']}}</label>
            <div class="row-input @if ($orderBaseFieldRow['is_must'] == 1) required @endif">
                <input name="base_{{$orderBaseFieldRow['field_name']}}"  value="@if(isset($orderBaseFieldRow['default_value'])) {{$orderBaseFieldRow['default_value']}} @endif" data-toggle="datepicker" data-rule="@if ($orderBaseFieldRow['is_must'] == 1) required @endif;date" type="text">
            </div>

            @elseif($orderBaseFieldRow['field_type'] == 8){{--添加配送信息--}}
            <label class="row-label">{{$orderBaseFieldRow['title']}}</label>
            <div class="row-input ">
                <button type="button" class="btn btn-info" data-toggle="dialog" data-options="{id:'add_distribution_dialog',fresh:false, url:'/admin/order/createOrderDistribution', title:'{{$orderBaseFieldRow['title']}}', data:{order_pre_id:{{$orderPreId}}}}"><i class="fa fa-edit"></i>{{$orderBaseFieldRow['title']}}</button>
            </div>

            @elseif($orderBaseFieldRow['field_type'] == 9){{--图片上传--}}
            <div style="width:100%">
            <label class="row-label">{{$orderBaseFieldRow['title']}}</label>
            <div class="row-input">
                <input type="file" data-name="base_{{$orderBaseFieldRow['field_name']}}[]" data-id="base_{{$orderBaseFieldRow['field_name']}}[]" data-toggle="webuploader" data-options="
                {
                    pick: {label: '点击选择图片'},
                    server: 'admin/photo/upload',
                    auto:true,
                    upname:'base_{{$orderBaseFieldRow['field_name']}}[]',
                    fileNumLimit: 5,
                    formData: {_token : '{{ csrf_token() }}',path_type:2},
                    required: false,
                    uploaded: '@if(isset($orderBaseFieldRow['default_img_url'])) {{$orderBaseFieldRow['default_img_url']}} @endif',
                    initUploaded: '@if(isset($orderBaseFieldRow['default_img_id'])) {{$orderBaseFieldRow['default_img_id']}} @endif',
                    basePath: '',
                    accept: {
                        title: '图片',
                        extensions: 'jpg,png',
                        mimeTypes: '.jpg,.png'
                    }
                }">
                {{--<input type="hidden" name="img_id" id="img_id" value="{{$info['img_id']}}">--}}
            </div>
            </div>

            @else{{--文本文档&&其他--}}
            <label class="row-label">{{$orderBaseFieldRow['title']}}</label>
            <div class="row-input @if ($orderBaseFieldRow['is_must'] == 1) required @endif">
                <input name="base_{{$orderBaseFieldRow['field_name']}}"  value="@if(isset($orderBaseFieldRow['default_value'])) {{$orderBaseFieldRow['default_value']}} @endif" data-rule="@if ($orderBaseFieldRow['is_must'] == 1) required @endif" type="text">
            </div>

            @endif
        @endforeach

        @foreach ($processList as $processRow)
            <h3>{{$processRow['process_title']}}</h3>
            @foreach ($processRow['process_field_list'] as $processFieldRow)
                @if($processFieldRow['field_type'] == 2){{--备注-文本域--}}
                <div style="width:100%">
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input @if ($processFieldRow['is_must'] == 1) required @endif" >
                    <textarea name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}" data-toggle="autoheight" cols="120" rows="3">@if(isset($processFieldRow['default_value'])) {{$processFieldRow['default_value']}} @endif</textarea>
                </div>
                </div>

                @elseif($processFieldRow['field_type'] == 3){{--下拉选择--}}
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input @if ($processFieldRow['is_must'] == 1) required @endif">
                    <select name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}" data-toggle="selectpicker" data-rule="@if ($processFieldRow['is_must'] == 1) required @endif">
                        <option value="">请选择</option>{{--空选项--}}
                        @foreach ($processFieldRow['data'] as $selectValue)
                            <option value="{{$selectValue['title']}}" @if(isset($processFieldRow['default_value']) && $processFieldRow['default_value'] == $selectValue['title']) selected="" @endif>{{$selectValue['title']}}</option>
                        @endforeach
                    </select>
                </div>

                @elseif($processFieldRow['field_type'] == 4){{--选择材料--}}
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input ">
                    <input name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}" type="hidden" value="@if(isset($processFieldRow['default_value'])) {{$processFieldRow['default_value']}} @endif" id = "id_material_{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}">
                    <button type="button" class="btn btn-info" data-toggle="dialog" data-options="{id:'pick_{{$processFieldRow['field_name']}}',width:'800',height:'600',fresh:true, url:'/admin/order/pickMaterial', title:'{{$processFieldRow['title']}}', data:{order_pre_id:{{$orderPreId}},process_id:{{$processRow['process_id']}},field_name:'{{$processFieldRow['field_name']}}' }}"><i class="fa fa-edit"></i>{{$processFieldRow['title']}}</button>
                </div>

                @elseif($processFieldRow['field_type'] == 5){{--文本+选择--}}
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input @if ($processFieldRow['is_must'] == 1) required @endif">
                    <input style="width:80%" name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}[]"  value="@if(isset($processFieldRow['default_value'])) {{$processFieldRow['default_value']}} @endif" data-rule="@if ($processFieldRow['is_must'] == 1) required @endif" type="text">

                    <select name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}[]" data-toggle="selectpicker" data-rule="@if ($processFieldRow['is_must'] == 1) required @endif">
                        <option value="">请选择</option>{{--空选项--}}
                        @foreach ($processFieldRow['field_unit'] as $unitValue)
                            <option value="{{$unitValue['title']}}" @if(isset($processFieldRow['default_unit_title']) && $processFieldRow['default_unit_title'] == $unitValue['title']) selected="" @endif>{{$unitValue['title']}}</option>
                        @endforeach
                    </select>
                </div>

                @elseif($processFieldRow['field_type'] == 6){{--开关按钮--}}
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input @if ($processFieldRow['is_must'] == 1) required @endif">
                    <input name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}" @if(isset($processFieldRow['default_value']) && ($processFieldRow['default_value'] == 1 )) checked="" @endif  data-toggle="icheck" value="1" data-rule="@if ($processFieldRow['is_must'] == 1) required @endif" data-label="是" type="radio">
                    <input name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}" @if(isset($processFieldRow['default_value']) && ($processFieldRow['default_value'] == 0 )) checked="" @endif  data-toggle="icheck" value="0" data-label="否" type="radio">
                </div>

                @elseif($processFieldRow['field_type'] == 7){{--日期--}}
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input @if ($processFieldRow['is_must'] == 1) required @endif">
                    <input name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}"  value="@if(isset($processFieldRow['default_value'])) {{$processFieldRow['default_value']}} @endif" data-toggle="datepicker" data-rule="@if ($processFieldRow['is_must'] == 1) required @endif;date" type="text">
                </div>

                @elseif($processFieldRow['field_type'] == 8){{--地址选择  工序模块不设置该字段--}}
                @elseif($processFieldRow['field_type'] == 9){{--上传图片  工序模块不设置该字段--}}
                @elseif($processFieldRow['field_type'] == 10){{--扫描二维码  工序模块不设置该字段--}}

                @elseif($processFieldRow['field_type'] == 11){{--双下拉联动--}}
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input @if ($processFieldRow['is_must'] == 1) required @endif">
                    <select id="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}" name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}[]"  data-rule="@if ($processFieldRow['is_must'] == 1) required @endif">
                        <option value="">请选择</option>{{--空选项--}}
                        @foreach ($processFieldRow['data'] as $data)
                            <option value="{{$data['id']}}" @if(isset($data['isSelect']) && $data['isSelect'] == 1) selected="" @endif>{{$data['title']}}</option>
                        @endforeach
                    </select>
                    <select id="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}_child" name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}[]" data-rule="@if ($processFieldRow['is_must'] == 1) required @endif">
                        <option value="">请选择</option>{{--空选项--}}
                        @if(isset($processFieldRow['selectChild']) && !empty($processFieldRow['selectChild']))
                            @foreach($processFieldRow['selectChild'] as $tmpData)
                                <option value="{{$tmpData['title']}}" @if(isset($tmpData['isSelect']) && $tmpData['isSelect'] == 1) selected="" @endif>{{$tmpData['title']}}</option>
                            @endforeach
                        @endif
                    </select>
                    <script>
                    select_arr['{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}'] = {};
                    @foreach ($processFieldRow['data'] as $data)
                        select_arr['{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}']['{{$data['id']}}']=[];
                            @if(isset($data['data']) && is_array($data['data']))
                            @foreach ($data['data'] as $dataDetail)
                                select_arr['{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}']['{{$data['id']}}'].push('{{$dataDetail['title']}}') ;
                            @endforeach
                            @endif
                    @endforeach
                    //选择框一变动时，触发事件
                    $('#{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}').change(function(){

                        var dataId = $('#{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}').val();
                        var html = '<option value="">请选择</option>';
                        $.each(select_arr['{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}'][dataId],function(name,value){
                            html += '<option value="'+value+'">'+value+'</option>';
                        });
                        $('#{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}_child').html(html);
                    });

                    </script>
                </div>

                @elseif($processFieldRow['field_type'] == 13){{--多个勾选--}}
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input @if ($processFieldRow['is_must'] == 1) required @endif">
                    @foreach ($processFieldRow['data'] as $data)
                        <div class="row-input"  style="width:100px;">
                            <input type="checkbox" name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}[]" id="set-process-action-{{$data['id']}}" value="{{$data['title']}}"
                                   data-toggle="icheck" data-label="{{$data['title']}}" @if(isset($data['isCheck']) && $data['isCheck']==1)checked="" @endif>
                        </div>
                    @endforeach
                </div>

                @else{{--文本文档&&其他--}}
                <label class="row-label">{{$processFieldRow['title']}}</label>
                <div class="row-input @if ($processFieldRow['is_must'] == 1) required @endif">
                    <input name="{{$processRow['process_id']}}_{{$processFieldRow['field_name']}}"  value="@if(isset($processFieldRow['default_value'])) {{$processFieldRow['default_value']}} @endif" data-rule="@if ($processFieldRow['is_must'] == 1) required @endif" type="text">
                </div>

                @endif
            @endforeach
        @endforeach
    </div>
</form>
</div>

<div class="bjui-pageFooter">
    <ul>
        <li><button type="button" class="btn-default" data-icon="save" onclick="createOrderSubmit();">保存</button></li>
        <li><button type="button" class="btn-close" data-icon="close">取消</button></li>
    </ul>
</div>

<script type="text/javascript">
    function createOrderSubmit() {
        BJUI.ajax('ajaxform', {
            url: '/admin/order/createOrderSubmit',
            form: $.CurrentNavtab.find('#create_order'),
            validate: false,
            loadingmask: true,
            callback: function (json) {
                if(json.code  == 0){
                    BJUI.navtab('closeTab','create_order_navtab');
                    //打开订单列表页
                    BJUI.navtab({
                        id: 'order-list',
                        url: '/admin/order/getOrderList',
                        title: '订单列表'
                    })
                }else{
                    BJUI.alertmsg('info', json.message);
                }
            }
        });
    }

</script>